<template>
  <pro-page>
    <pro-table-search>
      <a-form-model-item>
        <template #label>
          <span><a-icon type="smile-o" /> Name</span>
        </template>
        <a-input />
      </a-form-model-item>
      <a-form-model-item label="Age">
        <a-input-number />
      </a-form-model-item>
      <a-form-model-item label="Address">
        <a-input />
      </a-form-model-item>
      <a-form-model-item label="Tags">
        <a-select allow-clear>
          <a-select-option value="nice">NICE</a-select-option>
          <a-select-option value="developer">DEVELOPER</a-select-option>
          <a-select-option value="loser">LOSER</a-select-option>
        </a-select>
      </a-form-model-item>
    </pro-table-search>
    <pro-card>
      <pro-table :columns="columns" :data-source="data" :toolbar="{ title: '如何正确使用 ProTable 组件', tooltip: 'ProTable' }" :loading="loading" @loading="handleLoading">
        <template #name="{ text }">
          <a :style="{ color: styleVariables.blue }">{{ text }}</a>
        </template>
        <template #customTitle>
          <span><a-icon type="smile-o" /> Name</span>
        </template>
        <template #tags="{ record: { tags } }">
          <a-tag
            v-for="tag in tags"
            :key="tag"
            :color="tag === 'loser' ? 'volcano' : tag.length > 5 ? 'geekblue' : 'green'"
          >
            {{ tag.toUpperCase() }}
          </a-tag>
        </template>
        <template #action="{ record }">
          <a class="text-success">邀请{{ record.name }}</a>
          <a-divider type="vertical" />
          <a class="text-danger">删除</a>
          <a-divider type="vertical" />
          <pro-table-dropdown
            :menus="[
              { name: '导出', key: 'export' },
              { name: '打印', key: 'print' }
            ]"
            @select="key => { handleSelect(key, record) }"
          />
        </template>

        <template #table-toolbar-actions>
          <a-button type="primary">新增</a-button>
        </template>

        <template #table-toolbar-settings>
          <a-tooltip title="github">
            <a-icon type="github" />
          </a-tooltip>
        </template>

        <template #table-toolbar-ColumnSetting-extra>
          <a>测试</a>
        </template>
      </pro-table>
    </pro-card>
  </pro-page>
</template>

<script>
import styleVariables from 'style-variables'

const columns = [
  {
    dataIndex: 'name',
    key: 'name',
    slots: { title: 'customTitle' },
    scopedSlots: { customRender: 'name' }
  },
  {
    title: 'Age',
    dataIndex: 'age',
    key: 'age'
  },
  {
    title: 'Address',
    dataIndex: 'address',
    key: 'address'
  },
  {
    title: 'Tags',
    key: 'tags',
    dataIndex: 'tags',
    scopedSlots: { customRender: 'tags' }
  },
  {
    title: 'Action',
    key: 'action',
    scopedSlots: { customRender: 'action' }
  }
]

const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park',
    tags: ['nice', 'developer']
  },
  {
    key: '2',
    name: 'Jim Green',
    age: 42,
    address: 'London No. 1 Lake Park',
    tags: [ 'loser' ]
  },
  {
    key: '3',
    name: 'Joe Black',
    age: 32,
    address: 'Sidney No. 1 Lake Park',
    tags: ['cool', 'teacher']
  }
]
export default {
  data() {
    return {
      columns,
      data,
      styleVariables,
      loading: false
    }
  },
  methods: {
    handleLoading() {
      this.loading = true

      setTimeout(() => {
        this.loading = false
      }, 800)
    },
    handleSelect(key, record) {
      this.$message.info(key + ': ' + record.name)
    }
  }
}
</script>
